//
//  IndexRowView.swift
//  maozzi-rss
//
//  Created by 帽子 on 2020/5/30.
//  Copyright © 2020 帽子. All rights reserved.
//

import SwiftUI

struct IndexRowView: View {
    var indexItem: IndexItem
    var newsCount: Int

    var body: some View {
        HStack {
            Image(systemName: self.indexItem.imageName)
                .imageScale(.large)
            Text(self.indexItem.title)
            if self.newsCount > 0 && self.indexItem.title != "最近阅读" {
                Circle()
                    .fill(Color.red)
                    .frame(width: 10, height: 10)
            }
            Spacer()
            if self.newsCount > 0 && self.newsCount < 100 {
                Text(String(self.newsCount)).font(.subheadline).foregroundColor(.orange)
            } else if self.newsCount >= 100 {
                Text("99+").font(.subheadline).foregroundColor(.orange)
            }
        }.padding()
    }
}

struct IndexRowView_Previews: PreviewProvider {
    static var previews: some View {
        IndexRowView(indexItem: IndexItem(id: 1, title: "未读消息", category: "index", imageName: "message"), newsCount: 0)
    }
}
